package math.vector;

public class vec3f 
{
    
    public float x;
    public float y;
    public float z;
    
    
    public vec3f() 
    {
        this(0.0f, 0.0f, 0.0f);
    }
    
    public vec3f(float cx, float cy, float cz) 
    {
        this.x = cx;
        this.y = cy;
        this.z = cz;
    }
    
    public vec3f(float value)
    {
        this(value, value, value);
    }
    
    public vec3f(double cx, double cy, double cz) 
    {
        this((float) cx, (float) cy, (float) cz);
    }
    
    public vec3f(vec3f other) 
    {
        this(other.x, other.y, other.z);
    }
    
    
    //<editor-fold defaultstate="collapsed" desc="setTo">
    public void setTo(float xOther, float yOther, float zOther)
    {
        Vecmath.calcSetTo(
            xOther, yOther, zOther, // source
            this // dest
        );
    }
    
    public void setTo(vec3f other)
    {
        Vecmath.calcSetTo(
            other.x, other.y, other.z, // source
            this // dest
        );
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="setToZero">
    public void setToZero()
    {
        Vecmath.calcSetTo(
            0.0f, 0.0f, 0.0f, // source
            this // dest
        );
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="swapWith">
    public void swapWith(vec3f other)
    {
        vec3f vecTemp = new vec3f(other);
        other.setTo(this);
        this.setTo(vecTemp);
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="translate">
    public void translate(float dx, float dy, float dz)
    {
        Vecmath.calcTranslate(
            dx, dy, dz, // source
            this // dest
        );
    }
    
    public void translate(vec3f translate)
    {
        Vecmath.calcTranslate(
            translate.x, translate.y, translate.z, // source
            this // dest
        );
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="scale">
    public void scale(float xScale, float yScale, float zScale)
    {
        Vecmath.calcScale(
            xScale, yScale, zScale, // source
            this // dest
        );
    }
    
    public void scale(float xyzScale)
    {
        Vecmath.calcScale(
            xyzScale, xyzScale, xyzScale, // source
            this // dest
        );
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="limitToLength">
    public void limitToLength(float length)
    {
        Vecmath.calcLimitToLength(
            this.x, this.y, this.z,
            length,
            this
        );
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="invert">
    public void invert()
    {
        Vecmath.calcInvertedOf(this.x, this.y, this.z, this);
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="normalize">
    public void normalize()
    {
        Vecmath.calcNormalize(
            this.x, this.y, this.z, // source
            this // dest
        );
    }
    //</editor-fold>
    
    //<editor-fold defaultstate="collapsed" desc="getLength">
    public float getLength()
    {
        return Vecmath.getLengthOf(this);
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="getLengthSq">
    public float getLengthSq()
    {
        return Vecmath.getLengthSqOf(this);
    }
    //</editor-fold>
    
    public boolean equals(vec3f other) 
    {
        return Vecmath.getEquals(this, other);
    }
    
    public boolean isZero() 
    {
        return Vecmath.getEquals(this, Vecmath.ORIGIN);
    }
    
    public float[] asArray()
    {
        return new float[] {
            this.x, 
            this.y, 
            this.z
        };
    }
    
    public String toString() 
    {
        String s = "";
        s += "( ";
        s += String.format("%.3f", this.x) + ", ";
        s += String.format("%.3f", this.y) + ", ";
        s += String.format("%.3f", this.z);
        s += " )";
        return s;
    }
    
}